home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_se / creation_clause.e < prev    next >
Text File  |  1998-12-22  |  5KB  |  187 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CREATION_CLAUSE
  17.    --
  18.    -- The store the contents of one creation clause.
  19.    --   example 1
  20.    --                creation {ANY} make
  21.    --   example 2
  22.    --                creation make, foo
  23.    --   example 3
  24.    --                creation {NONE,ANY} make, foo
  25.    --   example 4
  26.    --                creation
  27.    -- 
  28.    -- Note : The original text of the source file can be stored
  29.    --        for pretty pretty_printing to be fine.
  30.    --
  31.  
  32. inherit GLOBALS;
  33.  
  34. creation make
  35.    
  36. feature
  37.  
  38.    start_position: POSITION;
  39.      -- Of the corresponding keyword.
  40.  
  41.    clients: CLIENT_LIST;
  42.  
  43.    comment: COMMENT;
  44.  
  45. feature {NONE}
  46.  
  47.    procedure_list: FEATURE_NAME_LIST;
  48.    
  49. feature
  50.    
  51.    make(sp: like start_position; c: like clients; 
  52.     cm: like comment; pl: like procedure_list) is
  53.       require
  54.      sp /= Void;
  55.      c /= Void;
  56.       do
  57.      start_position := sp;
  58.      clients := c;
  59.      comment := cm;
  60.      procedure_list := pl;
  61.       ensure
  62.      clients = c;
  63.      comment = cm
  64.      procedure_list = pl;
  65.       end;
  66.  
  67.    pretty_print is
  68.       local
  69.      i: INTEGER;
  70.       do
  71.      fmt.set_indent_level(0);
  72.      if not fmt.zen_mode then
  73.         fmt.skip(1);
  74.      else
  75.         fmt.indent;
  76.      end;
  77.      fmt.keyword("creation");
  78.      fmt.set_indent_level(1);
  79.      if clients /= Void then
  80.         clients.pretty_print;
  81.      end;
  82.      if comment /= void then
  83.         comment.pretty_print;
  84.      end;
  85.      fmt.set_indent_level(1);
  86.      if not fmt.zen_mode then
  87.         fmt.indent;
  88.      end;
  89.      if procedure_list /= Void then
  90.         procedure_list.pretty_print;
  91.      end;
  92.       end;
  93.          
  94.    short(heading_done: BOOLEAN): BOOLEAN is
  95.      -- True when at least one creation list is printed.
  96.       do
  97.      if clients.gives_permission_to_any then
  98.         if not heading_done then
  99.            short_print.hook_or("hook100","creation%N");
  100.         end;
  101.         if procedure_list /= Void then
  102.            procedure_list.short_for_creation;
  103.         end;
  104.         short_print.hook_or("hook101","");
  105.         Result := true;
  106.      else
  107.         eh.cancel;
  108.      end;
  109.       end;
  110.  
  111.    has(fn: FEATURE_NAME): BOOLEAN is
  112.       require
  113.      fn /= Void
  114.       do
  115.      if procedure_list /= Void then
  116.         Result := procedure_list.has(fn);
  117.      end;
  118.       end;
  119.    
  120. feature {CREATION_CLAUSE_LIST}
  121.    
  122.    root_procedure_name(procedure_name: STRING): SIMPLE_FEATURE_NAME is
  123.       do
  124.      if procedure_list = Void then
  125.      else
  126.         Result := procedure_list.root_procedure_name(procedure_name);
  127.      end;
  128.       end;
  129.  
  130.    check_expanded_with(t: TYPE) is
  131.       require
  132.      t.is_expanded;
  133.       local
  134.      rf: RUN_FEATURE;
  135.      rf3: RUN_FEATURE_3;
  136.      rc: RUN_CLASS;
  137.       do
  138.      if procedure_list = Void then
  139.         eh.add_position(start_position);
  140.         fatal_error("Cannot create a class with an empty creation list.");
  141.      end;
  142.      if procedure_list.count > 1 then
  143.         eh.add_type(t,fz_cbe);
  144.         eh.add_position(start_position);
  145.         fatal_error_vtec_2;
  146.      end;
  147.      rc := t.run_class;
  148.      rf := rc.get_feature(procedure_list.item(1));
  149.      if rf = Void then
  150.         eh.add_position(start_position);
  151.         eh.append("Creation procedure for ");
  152.         eh.add_type(t," not found.");
  153.         eh.print_as_fatal_error;
  154.      end;
  155.      rf3 ?= rf;
  156.      if rf3 = Void then
  157.         eh.add_position(start_position);
  158.         eh.add_position(rf.start_position);
  159.         fatal_error("Feature found is not a procedure.");
  160.      end;
  161.      if rf3.arg_count > 0 then
  162.         eh.add_type(t,fz_cbe);
  163.         eh.add_position(start_position);
  164.         eh.add_position(rf3.start_position);
  165.         eh.append("Procedure found has arguments. ");
  166.         fatal_error_vtec_2;
  167.      end;   
  168.       end;
  169.    
  170.    expanded_initializer(t: TYPE): RUN_FEATURE_3 is
  171.       require
  172.      t.is_expanded;
  173.      not t.is_basic_eiffel_expanded;
  174.      procedure_list.count = 1;
  175.       do
  176.      if procedure_list /= Void then
  177.         Result ?= t.run_class.get_feature(procedure_list.item(1));
  178.      end;
  179.       end;
  180.    
  181. invariant
  182.    
  183.    clients /= Void;
  184.    
  185. end -- CREATION_CLAUSE
  186.  
  187.